<template>
  <div class="ele-body">
    <el-card shadow="never">

      <!-- 搜索表单 -->
      <el-form style="margin-top: 10px"
               :model="where"
               label-width="77px"
               class="ele-form-search"
               @keyup.enter.native="reload"
               @submit.native.prevent>
        <el-row :gutter="15">
          <el-col :lg="6" :md="12">
            <el-form-item label="订单编号:">
              <el-input
                v-model="where.OrderID"
                placeholder="请输入订单编号"
                clearable/>
            </el-form-item>

          </el-col>
          <el-col :lg="6" :md="12">
            <el-form-item label="游戏ID:">
              <el-input
                v-model="where.UserID"
                placeholder="请输入游戏ID"
                clearable/>
            </el-form-item>

          </el-col>
          <el-col :lg="6" :md="12">
            <el-form-item label="兑换渠道:">
              <el-input
                v-model="where.ChannelID"
                placeholder="请输入兑换渠道"
                clearable/>
            </el-form-item>
          </el-col>
          <el-col :lg="6" :md="12">
            <el-form-item label="渠道类型:">
              <el-input
                v-model="where.ChannelID"
                placeholder="请选择兑换渠道类型"
                clearable/>
            </el-form-item>
          </el-col>
          <el-col :lg="6" :md="12">
            <el-form-item label="渠道类型:">
              <el-input
                v-model="where.ChannelID"
                placeholder="请选择兑换渠道类型"
                clearable/>
            </el-form-item>
          </el-col>
          <el-col :lg="6" :md="12">
            <el-form-item label="开始时间:">
              <el-date-picker
                type="datetime"
                class="ele-fluid"
                v-model="where.startTime"
                value-format="yyyy-MM-dd HH:mm:ss"
                placeholder="请选择开始时间"/>
            </el-form-item>
          </el-col>
          <el-col :lg="6" :md="12">
            <el-form-item label="结束时间:">
              <el-date-picker
                type="datetime"
                class="ele-fluid"
                v-model="where.endTime"
                value-format="yyyy-MM-dd HH:mm:ss"
                placeholder="请选择结束时间"/>
            </el-form-item>
          </el-col>
          <el-col :lg="6" :md="12">
            <div class="ele-form-actions">
              <el-button
                type="primary"
                @click="reload"
                icon="el-icon-search"
                class="ele-btn-icon">查询
              </el-button>
              <el-button @click="reset">重置</el-button>
            </div>
          </el-col>
        </el-row>
      </el-form>

      <!-- 数据表格 -->
      <ele-pro-table
        ref="table"
        :datasource="url"
        :columns="columns"
        :where="where"
        :page-size="20"
        row-key="OrderID"
        :expand-row-keys="expands"
        @row-click="clickRowHandle"
        height="calc(100vh - 315px)">
        <!-- 表头工具栏 -->
        <template slot="toolbar">
          <el-button
            @click="exportData"
            type="primary"
            class="ele-btn-icon"
            size="small"
          >批量通过
          </el-button>
        </template>
        <template slot="toolbar">
          <el-button
            @click="exportData"
            type="warning"
            class="ele-btn-icon"
            size="small"
          >批量扣留
          </el-button>
        </template>
        <template slot="toolbar">
          <el-button
            @click="exportData"
            type="info"
            class="ele-btn-icon"
            size="small"
          >批量退还
          </el-button>
        </template>
        <template slot="toolbar">
          <el-button
            @click="exportData"
            type="success"
            class="ele-btn-icon"
            size="small"
          >批量完成
          </el-button>
        </template>
        <template slot="toolbar">
          <el-button
            @click="exportData"
            type="primary"
            class="el-icon-edit"
            size="small"
          >批量备注
          </el-button>
        </template>
        <template slot="toolbar">
          <el-button
            @click="exportData"
            type="danger"
            class="el-icon-warning-outline"
            size="small"
          >疑似违规退还
          </el-button>
        </template>

        <el-table-column type="expand">
          <template slot-scope="scope">
            <div style="padding-left: 60px;">
              <h2 style="font-size: 14px;">题目选项</h2>
            </div>
            <div>
              <h2 style="font-size: 14px;">备注</h2>
              <div>{{ scope.row.description || '暂无备注' }}</div>
            </div>
          </template>
        </el-table-column>

        <!-- 操作类型列 -->
        <!-- 操作列 -->
        <!--        <template slot="action" slot-scope="{row}">-->
        <!--          <el-link-->
        <!--            type="primary"-->
        <!--            :underline="false"-->
        <!--            icon="el-icon-edit"-->
        <!--            @click="openEdit(row)"-->
        <!--            v-if="permission.includes('sys:channel:edit')">修改-->
        <!--          </el-link>-->

        <!--        </template>-->
      </ele-pro-table>
    </el-card>

    <!-- 编辑弹窗 -->
    <channel-edit
      :data="current"
      :visible.sync="showEdit"
      @done="reload"/>
  </div>
</template>

<script>
import {mapGetters} from "vuex";
import ChannelEdit from './exchange-edit.vue';


export default {
  name: 'SystemExchange',
  components: {ChannelEdit},
  computed: {
    ...mapGetters(["permission"]),
  },
  data() {
    return {
      // 表格数据接口
      url: '/admin/order.exchange/index',
      // 表格列配置
      columns: [
        {
          columnKey: 'selection',
          type: 'selection',
          width: 45,
          align: 'center',
          fixed: "left"
        },
        {
          prop: 'OrderID',
          label: '订单编号',
          width: 200,
          align: 'center',
          showOverflowTooltip: true,
          fixed: "left",

        },
        {
          prop: 'UserID',
          label: '游戏ID',
          width: 100,
          align: 'center',
          showOverflowTooltip: true,
          fixed: "left"
        },
        {
          prop: 'Amount',
          label: '兑换金额',
          align: 'center',
          showOverflowTooltip: true,
          minWidth: 100
        },
        {
          prop: 'Revenue',
          label: '手续费',
          align: 'center',
          showOverflowTooltip: true,
          minWidth: 100
        },
        {
          prop: 'Score',
          label: '兑换金币',
          align: 'center',
          showOverflowTooltip: true,
          minWidth: 100
        },
        {
          prop: 'Status',
          label: '订单状态',
          align: 'center',
          showOverflowTooltip: true,
          minWidth: 100
        },
        {
          prop: 'ChannelID',
          label: '兑换渠道',
          align: 'center',
          showOverflowTooltip: true,
          minWidth: 100
        },
        {
          prop: 'OrderType',
          label: '兑换类型',
          align: 'center',
          showOverflowTooltip: true,
          minWidth: 100
        },
        // {
        //   prop: 'OrderType',
        //   label: '游戏局数',
        //   align: 'center',
        //   showOverflowTooltip: true,
        //   minWidth: 100
        // },
        // {
        //   prop: 'OrderType',
        //   label: '总充值',
        //   align: 'center',
        //   showOverflowTooltip: true,
        //   minWidth: 100
        // },
        // {
        //   prop: 'OrderType',
        //   label: '总兑换',
        //   align: 'center',
        //   showOverflowTooltip: true,
        //   minWidth: 100
        // },
        // {
        //   prop: 'OrderType',
        //   label: '游戏写分',
        //   align: 'center',
        //   showOverflowTooltip: true,
        //   minWidth: 100
        // },
        {
          prop: 'CollectDate',
          label: '下单时间',
          align: 'center',
          showOverflowTooltip: true,
          minWidth: 180
        },
        {
          prop: 'UpdateDate',
          label: '完成时间',
          align: 'center',
          showOverflowTooltip: true,
          minWidth: 180
        },
        // {
        //   prop: 'OrderType',
        //   label: '备注信息',
        //   align: 'center',
        //   showOverflowTooltip: true,
        //   minWidth: 100
        // },
        // {
        //   prop: 'OrderType',
        //   label: '收款信息',
        //   align: 'center',
        //   showOverflowTooltip: true,
        //   minWidth: 100
        // },
        // {
        //   columnKey: 'action',
        //   label: '操作',
        //   width: 90,
        //   align: 'center',
        //   resizable: false,
        //   slot: 'action',
        //   fixed: "right"
        // }
      ],
      // 表格搜索条件
      where: {},
      // 当前编辑数据
      current: null,
      // 是否显示编辑弹窗
      showEdit: false,
      // 要展开的行，数值的元素是row的key值
      expands: [],
      getRowKeys(row) {
        return row.OrderID;
      },
      // 筛选日期范围
      // daterange: null,
      // 日期时间选择器快捷项
    };
  },
  methods: {
    /* 刷新表格 */
    reload() {
      this.$refs.table.reload({where: this.where});
    },
    /* 重置搜索 */
    reset() {
      this.where = {};
      this.daterange = null;
      this.reload();
    },
    openEdit(row) {
      console.log(row)
      this.current = row;
      this.showEdit = true;
    },
    clickRowHandle(row, column, event) {
      console.log(row)
      console.log(column)
      console.log(event)
      if (this.expands.includes(row.OrderID)) {
        this.expands = this.expands.filter(val => val !== row.id);
      } else {
        this.expands.push(row.OrderID);
      }
    },

    /* 日期选择改变回调 */
  }
}
</script>

<style scoped>
</style>
